package com.meida.module.bus.provider.service.impl;

import com.meida.common.mybatis.base.service.impl.BaseServiceImpl;
import com.meida.common.mybatis.entity.EntityMap;
import com.meida.common.mybatis.model.ResultBody;
import com.meida.common.mybatis.query.CriteriaQuery;
import com.meida.common.mybatis.query.CriteriaSave;
import com.meida.module.bus.client.entity.BusMaterial;
import com.meida.module.bus.client.entity.BusMaterialView;
import com.meida.module.bus.provider.mapper.BusMaterialViewMapper;
import com.meida.module.bus.provider.service.BusMaterialViewService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.Map;

/**
 * VIEW接口实现类
 *
 * @author flyme
 * @date 2020-10-21
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class BusMaterialViewServiceImpl extends BaseServiceImpl<BusMaterialViewMapper, BusMaterialView> implements BusMaterialViewService {

    @Override
    public ResultBody beforeAdd(CriteriaSave cs, BusMaterialView bmv, EntityMap extra) {
        return ResultBody.ok();
    }



    @Override
    @Transactional(propagation = Propagation.NOT_SUPPORTED, readOnly = true)
    public ResultBody beforePageList(CriteriaQuery<BusMaterialView> cq, BusMaterialView bmv, EntityMap requestMap) {
      cq.orderByDesc("bmv.createTime");
      return ResultBody.ok();
    }

    @Override
    public BusMaterialView getBusMaterialView(Map map){
        CriteriaQuery<BusMaterialView> cq=new CriteriaQuery<BusMaterialView>(BusMaterialView.class);
        cq.select("bmv.brandName," +
            "	bmv.contractDesc," +
            "	bmv.contractMainPrice1," +
            "	bmv.contractMainPrice2," +
            "	bmv.contractMainPrice3," +
            "	bmv.contractOtherPrice1," +
            "	bmv.contractOtherPrice2," +
            "	bmv.contractOtherPrice3," +
            "   bmv.contractInstallPrice1," +
            "   bmv.contractInstallPrice2," +
            "   bmv.contractInstallPrice3," +
            "   bmv.serviceCode ," +
            "   bmv.serviceWbsCode," +
            "	bmv.costQuantity100," +
            "	bmv.costQuantity200," +
            "	bmv.levelNo," +
            "   bmv.majorName," +
            "   bmv.majorCode," +
            "	bmv.materialArea," +
            "	bmv.materialCode," +
            "	bmv.materialDesc," +
            "	bmv.materialName," +
            "   bmv.packageDesc," +
            "	bmv.materialUse," +
            "	bmv.materialWbsCode," +
            "	bmv.materiaSpecs," +
            "	bmv.packageName," +
            "	bmv.packageNo," +
            "	bmv.remark," +
            "	bmv.subjectName," +
            "	bmv.technicalData," +
            "	bmv.createTime as insertDate,bmv.projectId,bmv.materialPlanId,material.*");
        cq.createJoin(BusMaterial.class).setMainAlias("materialId").setJoinField("materialId");
        cq.eq("materialPlanId",map.get("materialPlanId"));
        return getOne(cq);
    }
}
